﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FarseerGames.FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.FarseerPhysics;

namespace Matryoshka
{
    public class FontDecal : Decal
    {
        Body body;

        string text;

        SpriteFont font;

        Color color = Color.Yellow;
        float scale = 1f;

        public Color dColor = Color.TransparentBlack;
        public float dScale = 0f;

        public FontDecal(PhysicsSimulator physicsSimulator, SpriteFont font, string text, Vector2 pos, Vector2 force)
        {
            this.font = font;
            this.text = text;

            body = BodyFactory.Instance.CreateBody(physicsSimulator, 1f, 1f);
            body.IgnoreGravity = true;
            body.Position = pos;
            body.ApplyForce(force);
            
            UpdateEvent += new UpdateEventHandler(FontDecal_UpdateEvent);
        }

        void FontDecal_UpdateEvent(object sender, UpdateEventArgs e)
        {
            color.R -= dColor.R;
            color.G -= dColor.G;
            color.B -= dColor.B;
            color.A -= dColor.A;
            scale -= dScale;

            if (color.A < 10)
            {
                done = true;
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, text, body.Position, color, body.Rotation, Vector2.Zero, scale, SpriteEffects.None, 0f);
        }
    }
}
